function websocketRouter(ws, req) {
  console.log("connect success");
  ws.on("message", function (msg) {
    console.log(`receive message ${msg}`);
  });

  ws.on("close", function (e) {
    console.log("close connection");
  });

  switch (req.query.task) {
    case "train":
      if (req.query.monitor === "log") {
        req.app.locals.wsTrainLog = ws;
      }
      if (req.query.monitor === "chart") {
        req.app.locals.wsTrainChart = ws;
      }
      break;
    case "test":
      if (req.query.monitor === "log") {
        req.app.locals.wsTestLog = ws;
      }
      if (req.query.monitor === "chart") {
        req.app.locals.wsTestChart = ws;
      }
      if (req.query.monitor === "result") {
        req.app.locals.wsTestResult = ws;
      }
      break;
    default:
  }
  return;
}

module.exports = websocketRouter;
